<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('产品运行监测表') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('基金名称')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('基金名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('年度')" prop="year">
        <el-date-picker
          v-model="queryParams.year"
          type="year"
          :placeholder="$t('年度')"
          value-format="yyyy"
        />
      </el-form-item>
      <el-form-item :label="$t('季度')" prop="quarterly">
        <dict-select
          v-model="queryParams.quarterly"
          dictionary="sys_quarter"
          :placeholder="$t('季度')"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:monitor:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="fundProductOperationMonitorList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle" min-width="200">
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金简称')" align="center" prop="fundName" min-width="200">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/fundBasehome', query:{ id: scope.row.fundId }}"
            class="link_a"
          >{{ $t(scope.row.fundName) }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('年度')" align="center" prop="year" min-width="150" />
      <el-table-column :label="$t('季度')" align="center" prop="quarterly" :formatter="quarterlyFormat" min-width="150" />
      <el-table-column :label="$t('审批状态')" show-overflow-tooltip align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="350">
        <template slot-scope="scope">
          <div style="display: flex;column-gap: 10px;justify-content: center;">
            <el-button
              v-if="scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D'"
              v-hasPermi="['fund:monitor:edit']"
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="updateHandle(scope.row)"
            >{{ $t('修改') }}</el-button>
            <el-button
              v-if="scope.row.actStatus !== 'W' && scope.row.actStatus !== 'D'"
              v-hasPermi="['fund:monitor:edit']"
              size="small"
              type="text"
              icon="el-icon-setting"
              style="margin:0;"
              @click="editIndicatorHandle(scope.row)"
            >{{ $t('填写') }}</el-button>
            <el-button
              v-if="scope.row.exportProcessBtn"
              v-hasPermi="['fund:monitor:export']"
              type="text"
              icon="el-icon-download"
              size="small"
              style="float: left;"
              @click="exportHandle(scope.row)"
            >{{ $t("导出") }}</el-button>
            <ListBtn :bus-data="scope.row" has-permi="fund:monitor" :other-btn="!(scope.row.processBtn || scope.row.exportProcessBtn)" style="display: flex;" />
          </div>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品运行监测对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" width="30%" append-to-body>
      <fundProductOperationMonitorForm ref="fundProductOperationMonitorForm" />
    </el-dialog>

    <!-- 填写指标 -->
    <el-dialog :title="$t('填写指标')" :visible.sync="indicatorFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm dialogFormPcwMedical" append-to-body>
      <fundProductOperationMonitorHome ref="fundProductOperationMonitorHome" />
    </el-dialog>
  </div>
</template>

<script>
import { listFundProductOperationMonitor, delFundProductOperationMonitor } from '@/api/fund/operation/fundProductOperationMonitor'
import fundProductOperationMonitorForm from './fundProductOperationMonitorForm.vue'
import fundProductOperationMonitorHome from '@/views/fund/operation/fundProductOperationMonitorHome.vue'

export default {
  components: {
    fundProductOperationMonitorHome,
    fundProductOperationMonitorForm
  },
  data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 产品运行监测表格数据
        fundProductOperationMonitorList: [],
        // 弹出层标题
        title: this.$t('产品运行监测表'),
        // 是否显示弹出层
        formOpen: false,
        indicatorFormOpen: false,
        // 季度字典
        quarterlyOptions: [],
          // 查询参数
          queryParams: {
              fundName: undefined,
              year: undefined,
              quarterly: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // tabs 选择值
          activeName: undefined,
          // 表单校验
          rules: {}
      }
  },
  created() {
    this.getDicts('sys_quarter').then(response => {
      this.quarterlyOptions = response.data
    })
      this.getList()
  },
  methods: {
    /** 查询产品运行监测列表 */
    getList() {
        this.loading = true
        listFundProductOperationMonitor(this.queryParams).then(response => {
            this.fundProductOperationMonitorList = response.rows
            this.fundProductOperationMonitorList.forEach(item => {
              if (item.actStatus === 'D') {
                // 启动或完成的流程按钮状态关闭
                item.processBtn = false
                item.exportProcessBtn = false
              } else if (item.actStatus === 'W') {
                item.exportProcessBtn = true
              } else {
                // 未启动或终止流程按钮状态开启
                item.exportProcessBtn = false
                item.processBtn = true
              }
            })
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            fundId: undefined,
            year: undefined,
            quarterly: undefined,
            delFlag: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    // 季度字典翻译
    quarterlyFormat(row) {
      return this.selectDictLabel(this.quarterlyOptions, row.quarterly)
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.fundProductOperationMonitorForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.fundProductOperationMonitorForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delFundProductOperationMonitor(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle(row) {
      this.downLoadExcel('/operation/fundProductIndicator/export', { monitorId: row.id })
    },
    // 填写指标
    editIndicatorHandle(row) {
      this.indicatorFormOpen = true
      this.$nextTick(() => {
        this.$refs.fundProductOperationMonitorHome.init(row)
      })
    }
  }
}
</script>
